package com.stockz.ui.swing.charting.display.indicator;

import java.awt.Graphics2D;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.stockz.core.model.Bar;
import com.stockz.ui.swing.charting.painter.indicator.LineIndicatorPainter;
import com.stockz.ui.swing.charting.util.UIChartingConstant.OVERLAY;

@Component
@Scope("prototype")
public class AccumulationDistribution extends
		AbstractDisplayableIndicatorConfiguration{
	
	@Override
	public String getFullName() {
		return "Accumulation/Distribution";
	}

	@Override
	public String getShortName() {
		return "A/D";
	}

	@Override
	public String getDescription() {
		return getFullName();
	}

	@Override
	public OVERLAY getOverlay() {
		return OVERLAY.INDEPENDENT;
	}

	@Override
	public boolean isOverlappable() {
		return true;
	}

	@Override
	public void paint(Graphics2D g) {
		LineIndicatorPainter.paint(g, this);
	}

	@Override
	public Object getConfiguration() {
		return null;
	}

	@Override
	public void refreshValues() {
		List<Bar> barList = getStockChartPanel().getStockChartPanelState().getBarList();
		if(barList != null && barList.size() > 1){
			double[] values = new double[barList.size()];
			double sum = 0;
			for(int i = barList.size()-1; i >= 0; i--){
				Bar bar = barList.get(i);
				if((bar.getHigh() - bar.getLow()) == 0){
					continue;
				}
				sum += ((bar.getClose() - bar.getLow()) - (bar.getHigh() - bar.getClose()))*bar.getVolume()/(bar.getHigh() - bar.getLow());
				values[i] = sum;
			}
			setValues(values);
		}
	}
	
}
